import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/custom_password_field.dart';

///支付界面
class InputPassword extends StatefulWidget {
  ///
  final OverlayEntry payBox;

  ///
  const InputPassword({Key key, this.payBox}) : super(key: key);

  @override
  _InputPasswordState createState() => _InputPasswordState();
}

class _InputPasswordState extends State<InputPassword> {
  String passWord = ""; // 密码
  List<String> keyboard = ["1", "2", "3", "4", "5", "6", "4", "8", "9"]; //键盘
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromARGB(102, 0, 0, 0),
      body: Stack(
        children: [
          Align(
            alignment: Alignment.bottomCenter,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Container(
                  margin:
                      EdgeInsets.only(left: setWidth(38), right: setWidth(38)),
                  padding: EdgeInsets.only(
                      top: setWidth(13),
                      left: setWidth(15),
                      right: setWidth(15)),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(8)),
                  height: setWidth(223),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        children: [
                          GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () {
                              ///移除支付界面
                              widget.payBox.remove();
                            },
                            child: Container(
                              padding: EdgeInsets.all(setWidth(5)),
                              width: setWidth(25),
                              height: setWidth(25),
                              child: Image.asset("assets/images/pay_close.png",
                                  fit: BoxFit.cover),
                            ),
                          ),
                        ],
                      ),
                      Container(
                        child: Text(
                          "请输入支付密码",
                          style: TextStyle(
                              color: Color(0xff333333),
                              fontSize: setSp(20),
                              fontWeight: FontWeight.w600),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: setWidth(14)),
                        height: setWidth(20),
                        child: Text(
                          "支付密码不正确",
                          style: TextStyle(
                              color: Color(0xffFF0000), fontSize: setSp(14)),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: setWidth(14)),
                        height: setWidth(44),
                        width: setWidth(273),
                        child: CustomPasswordField(passWord),
                      ),
                      GestureDetector(
                        onTap: () {
                          ///移除支付界面
                          widget.payBox.remove();
                          urlPush(context, "yuntu://set_password");
                        },
                        child: Container(
                          margin: EdgeInsets.only(top: setWidth(26)),
                          child: Text(
                            "忘记密码",
                            style: TextStyle(
                                color: Color(0xff00C65F), fontSize: setSp(14)),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  height: setWidth(73),
                ),
                //键盘
                Container(
                    color: Color(0xffE3E8EE),
                    height: setWidth(223),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Wrap(
                          children: keyboard
                              .asMap()
                              .map((key, value) {
                                return MapEntry(
                                    key,
                                    GestureDetector(
                                      onTap: () {
                                        if (passWord.length < 6) {
                                          setState(() {
                                            passWord = passWord + value;
                                          });
                                        } else {
                                          toast("密码超长");
                                        }
                                      },
                                      child: Container(
                                          alignment: Alignment.center,
                                          width: setWidth(375) / 3,
                                          height: setWidth(56),
                                          decoration: BoxDecoration(
                                              color: Colors.white,
                                              border: Border(
                                                top: BorderSide(
                                                    color: Color(0xffE6E7E9),
                                                    width: setWidth(0.5)),
                                                right: BorderSide(
                                                    color: Color(0xffE6E7E9),
                                                    width: setWidth(0.5)),
                                              )),
                                          child: Text(
                                            value,
                                            style: TextStyle(
                                                color: Color(0xff333333),
                                                fontSize: setSp(30)),
                                          )),
                                    ));
                              })
                              .values
                              .toList(),
                        ),
                        Expanded(
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                child: Container(
                                  width: setWidth(375) / 3,
                                  color: Color(0xffE3E8EE),
                                ),
                                flex: 1,
                              ),
                              Expanded(
                                child: GestureDetector(
                                  onTap: () {
                                    if (passWord.length < 6) {
                                      setState(() {
                                        passWord = passWord + "0";
                                      });
                                    } else {
                                      toast("密码超长");
                                    }
                                  },
                                  child: Container(
                                      alignment: Alignment.center,
                                      width: setWidth(375) / 3,
                                      height: setWidth(56),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          border: Border.all(
                                              color: Color(0xffE6E7E9),
                                              width: setWidth(0.5))),
                                      child: Text(
                                        "0",
                                        style: TextStyle(
                                            color: Color(0xff333333),
                                            fontSize: setSp(30)),
                                      )),
                                ),
                                flex: 1,
                              ),
                              //删除
                              Expanded(
                                child: GestureDetector(
                                  onTap: () {
                                    if (passWord.isNotEmpty) {
                                      setState(() {
                                        passWord = passWord.substring(
                                            0, passWord.length - 1);
                                      });
                                    } else {
                                      toast("请输入密码");
                                    }
                                    print(passWord);
                                  },
                                  child: Container(
                                    alignment: Alignment.center,
                                    color: Color(0xffE3E8EE),
                                    child: Image.asset(
                                      "assets/images/delete_password.png",
                                      width: setWidth(27),
                                      height: setWidth(19),
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                ),
                                flex: 1,
                              ),
                            ],
                          ),
                        )
                      ],
                    ))
              ],
            ),
          )
        ],
      ),
    );
  }
}
